package com.zxl.app;
 
import java.io.File;
import java.nio.file.Paths;
import java.util.List;

import com.zxl.api.Greeting;
import org.pf4j.JarPluginManager;
import org.pf4j.PluginManager;
 

public class Main {

    private static final String SUFFIX_NAME = "myplugins";
 
    public static void main(String[] args) {
        // jar插件管理器
        PluginManager pluginManager = new JarPluginManager();
 
        // 加载指定路径插件
        pluginManager.loadPlugin(Paths.get(SUFFIX_NAME+File.separator+"plugin1-1.1-SNAPSHOT.jar"));

        // 通过pluginName去加载对应的PLUGIN
        String pluginName = "plugin1";
        // 启动指定插件(也可以加载所有插件)
        pluginManager.startPlugin(pluginName);
 
        // 得到插件并执行插件
        List<Greeting> greetings = pluginManager.getExtensions(Greeting.class);
        for (Greeting greeting : greetings) {
            System.out.println(">>> " + greeting.getGreeting());
        }
 
        // 停止并卸载指定插件
        pluginManager.stopPlugin(pluginName);
        pluginManager.unloadPlugin(pluginName);
 
    }
}